package cn.summit.controller;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import cn.summit.entity.Trade;
import cn.summit.repo.TradeRepo;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author summit
 * @since 2021/11/26 16:52
 */
@RestController
@RequestMapping("/demo")
@Slf4j
public class DemoController {

	@Autowired
	private TradeRepo tradeRepo;


	@GetMapping("/get")
	public void test() {
		List<Trade> all = tradeRepo.getAll();
		Specification <Trade> spec = new Specification<Trade>() {
			@Override
			public Predicate toPredicate(Root<Trade> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				//cb:构建查询，添加查询方式   like：模糊匹配
				//root：从实体Customer对象中按照custName属性进行查询
				return cb.like(root.get("custName").as(String.class), "1111%");
			}
		};
		log.info("info {}", all);
	}


	@GetMapping("/get1")
	public void test1() {
		tradeRepo.getData("id");
	}
}
